<template>
    <view class="wen">
		<h1>{{ news.title }}</h1>
		<img :src="news.img_url" alt="" />
		<span>{{ news.source }} &nbsp;<span style="font-size: 15px;">{{ news.datetime }}</span></span>
		<p>&nbsp;&nbsp;{{ news.content }}</p>
	</view>
</template>

<script>
export default {
  data() {
    return {
      news: '',
      newsId: ''
    }
  },
  methods: {
	async requestNewsDetail() {
	  const res = await this.$myRequest({
	    url: '/newsdetail',
	    method: 'POST',
	    data: {
	      newsId: this.newsId
	    }
	  })
	  console.log(res)
	  res.data[0].datetime = new Date(res.data[0].datetime).toLocaleDateString()
	  this.news = res.data[0]
	  uni.setNavigationBarTitle({
	    title: res.data[0].title
	  })
	},
	load(e) {
		this.newsId = e
		this.requestNewsDetail()
	}
  },
  onLoad(options) {
	console.log(options)	
	this.load(options.id)
  }
}
</script>

<style lang="scss">
.wen {
  text-align: center;
  padding: 20px;
  border: 1px solid #eee;
  border-radius: 8px;
  margin: 20px;

  img {
    width: 100%;
    height: 40%;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  }

  h1 {
    font-size: 24px;
    color: #222;
    margin-bottom: 15px;
  }

  p {
    font-size: 16px;
    line-height: 1.6;
    color: #333;
    text-align: left;
    margin-top: 20px;
  }
  span {
	  color: #a4a3a7;
  }
}

@media (max-width: 768px) {
  .wen {
    padding: 10px;
  }

  img {
    height: 60%;
  }

  h1 {
    font-size: 20px;
  }
}
</style>